package com.dp.mallchat.common.chat.service.strategy;

import com.dp.mallchat.common.chat.dao.MessageDao;
import com.dp.mallchat.common.chat.domain.entity.Message;
import com.dp.mallchat.common.chat.domain.enums.MessageTypeEnum;
import com.dp.mallchat.common.chat.domain.vo.req.msg.ImgMsgDTO;
import com.dp.mallchat.common.chat.domain.vo.req.msg.MessageExtra;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @Author: dupeng
 * @CreateTime: 2024-06-28  17:39
 * @Description: 图片处理
 */
@Component
public class ImgMsgHandler extends AbstractMsgHandler<ImgMsgDTO>{

    @Autowired
    private MessageDao messageDao;

    @Override
    protected void checkMsg(ImgMsgDTO body, Long roomId, Long uid) {
        super.checkMsg(body, roomId, uid);
    }

    @Override
    MessageTypeEnum getMsgType() {
        return MessageTypeEnum.IMG;
    }

    @Override
    protected void saveMsg(Message message, ImgMsgDTO body) {
        MessageExtra extra = Optional.ofNullable(message.getExtra()).orElse(new MessageExtra());
        extra.setImgMsgDTO(body);
        Message update = new Message();
        update.setId(message.getId());
        update.setExtra(extra);
        messageDao.updateById(update);
    }

    @Override
    public Object showMsg(Message msg) {
        return msg.getExtra().getImgMsgDTO();
    }

    @Override
    public Object showReplyMsg(Message msg) {
        return "图片";
    }

    @Override
    public String showContactMsg(Message msg) {
        return "[图片]";
    }
}
